#!/bin/bash
# shell script to execute heat analysis recursively

clear

echo " "
echo "----------------------------------------------------------"
echo "               PARTICLE LASER INTERACTION                 "
echo "                  Multiple Test Cases                     "
echo "                   Sigfried Haering                       "
echo "            The Univeristy of Texas at Austin             "
echo "                         2011                             " 
echo "----------------------------------------------------------"
echo " "
echo " compiling source code ..."
make clean
make
echo " "

if [ -e ./heat ]; then
   echo "Success!"
   echo "running compiled program, this may take awhile..."
   echo "----------------------------------------------------------"
   
   cd ../inputs 
   RADIUS=`cat radii.txt`
   FLUENCE=`cat fluences.txt`
   PULSE=`cat pulses.txt`
   cd ../code
   COUNTER=0
   
   for rnumber in `echo $RADIUS`
   do
      for fnumber in `echo $FLUENCE`
      do
         for pnumber in `echo $PULSE`
         do
	    let COUNTER=COUNTER+1
            echo " >>> RUNNNING CASE $COUNTER: radius: $rnumber fluence: $fnumber pulse: $pnumber"
	    cd ../inputs
	    sed "1 s/.*/$rnumber\, radius/" ns_param.txt > ns_param.temp
	    mv ns_param.temp ns_param.txt
	    sed "3 s/.*/$pnumber\, tau_fwhm/" ns_param.txt > ns_param.temp
	    mv ns_param.temp ns_param.txt
	    sed "4 s/.*/$fnumber\, applied fluence/" ns_param.txt > ns_param.temp
	    mv ns_param.temp ns_param.txt
	    sed "12 s/.*/t$COUNTER\.txt\, result file/" ns_param.txt > ns_param.temp
	    mv ns_param.temp ns_param.txt
	    cd ../code
	    ./heat 
         done
      done
   done

else
   echo "Compile Failed..."
fi
echo " "
echo "----------------------------------------------------------"
echo " "

echo " "
exit 0